$(function () {
  //手机号验证
  $('.btn-primary').click(function () {
    const iphoneNum = $('.login-form .ipt:eq(0)').find('input').val()
    const reg = /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/
    if (!reg.test(iphoneNum)) return alert('请输入正确的手机号')
    // 密码验证
    const pwd = $('.login-form .ipt:eq(1)').find('input').val()
    if (!pwd.trim()) return alert('请输入密码')
    // 请求ajax
    $.ajax({
      method: 'post',
      url: 'http://127.0.0.1:8060/index/login',
      data: {
        mobile: iphoneNum - 0,
        password: pwd,
      },
      success: (res) => {
        if (res.errno !== 0) alert(errmsg)
        localStorage.setItem('userToken', res.data.token)
        location.href = 'user.html'
      },
    })
  })
})
